package com.atguigu.springcloud.controller;


import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.hibernate.validator.internal.util.logging.Log_$logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import sun.security.krb5.internal.PAData;

import javax.annotation.Resource;
import java.util.List;
import java.util.logging.Logger;

@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment){
        int result= paymentService.create(payment);

        if(result>0){
            return new CommonResult<Integer>(200,"支付订单插入成功！serverPort:"+serverPort,result);
        }else{
            return new CommonResult<Integer>(404,"插入失败！",result);
        }
    }

    @GetMapping("/select/{id}")
    public CommonResult getPayment(@PathVariable("id") Long id){

        Payment payment= paymentService.getPayment(id);
        if (payment!=null){
            return new CommonResult<Payment>(200,"成功查询！serverPort:"+serverPort,payment);
        }else{
            return new CommonResult<Payment>( 404,"查询失败:"+id,null);
        }
    }

    @GetMapping("/selectAll")
    public String getAllPayment(){
        List<Payment> list=paymentService.getAllPayment();

        return list.toString();
    }
    @GetMapping("/lb")
    public String getPaymentLB(){
        return serverPort;
    }

}
